<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>酒店活动</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//unpkg.com/layui@2.9.21/dist/css/layui.css" rel="stylesheet">
    <script src="../jquery/jquery-3.6.0.js"></script>
</head>
<body>
<script>
    var value = sessionStorage.getItem("admin");

    if (value ===null){
        alert("请先登录!")
        window.location.href = "../login/login.html"
    }
</script>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header" style="background-color: #c0c4cc">
        <div class="layui-logo layui-hide-xs layui-bg-black">酒店预定管理系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">
                    <span id="head_user"></span>
                    <script>
                        var value = sessionStorage.getItem("name");
                        document.getElementById("head_user").textContent=value
                    </script>
                </a>
            </li>
            <!--            注释了右侧框-->
            <!--            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>-->
            <!--                <a href="javascript:;">-->
            <!--                    <i class="layui-icon layui-icon-more-vertical"></i>-->
            <!--                </a>-->
            <!--            </li>-->
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll" style="background-color:sandybrown;">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test" style="background-color:sandybrown">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">个人信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="person_information.html">个人信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">酒店订单管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="OrderList.html">预定房间订单</a></dd>
                        <dd><a href="checkinList.html">已入住房间订单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">客房信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guestroom_list.html">客房列表</a></dd>
                        <dd><a href="roomType.html">房间类型</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">酒店活动管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="activity.html">活动管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">会员管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="member_management.html">会员列表</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <blockquote class="layui-elem-quote layui-text">
                <span class="layui-breadcrumb">
                    <a href="index.html">首页</a>
                    <a><cite>酒店活动管理</cite></a>
                    <a><cite>活动管理</cite></a>
                </span>
            </blockquote>
<!--            表格-->
            <table class="layui-hide" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="addAct">添加酒店活动</button>
                </div>
            </script>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
            <script type="text/html" id="insert_form">
                <div class="layui-field-box">
                    <div class="layui-form-item layui-form-pane">
                        <label class="layui-form-label">活动标题</label>
                        <div class="layui-input-inline">
                            <input type="text" id="insert_title" class="layui-input" placeholder="请输活动标题">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text"> <label class="layui-form-label">输入活动内容</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea" id="insert_context"></textarea>
                        </div>
                    </div>
                </div>
            </script>

            <script src="../layui/layui.js" charset="utf-8"></script>
            <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
            <script>
                tableFlush();
                function tableFlush(){
                    layui.use('table', function(){
                        var table = layui.table;
                        table.render({
                            elem: '#test'
                            ,url:'/room/selectActAll'
                            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                            ,cols: [[
                                {title:'活动标题', width:250, templet: function(res){
                                        return '<em>'+ res.title +'</em>'
                                    }},
                                {title:'活动内容', width:250,  templet: function(res){
                                        return '<em>'+ res.context +'</em>'
                                    }},
                                {title:'发布时间', width:250, templet: function(res){
                                        return '<em>'+ res.pub_date +'</em>'
                                    }}
                                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:250}
                            ]]
                            ,page: true,
                        });

                        //头工具栏事件
                        table.on('toolbar(test)', function(obj){
                            var checkStatus = table.checkStatus(obj.config.id);
                            switch(obj.event) {
                                case 'addAct':
                                    layer.open({     // 弹出框处理  模态框
                                        type: 1               // 模态框
                                        ,title: '新增活动' //不显示标题栏
                                        ,closeBtn: false
                                        ,area: ['500px','500px']  // 宽和高
                                        ,shade: 0.5
                                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                                        ,btn: ['添加', '取消']
                                        ,btnAlign: 'c'
                                        ,moveType: 1 //拖拽模式，0或者1
                                        ,content: $('#insert_form').html()         // 引入自定义表单
                                        ,btn1: function(index, layero){            // 这个是新增按钮点击事件
                                            // layer.msg("新增按钮执行");
                                            let title = $("#insert_title").val();
                                            let context = $("#insert_context").val();
                                            $.ajax({
                                                url:"/room/insertActivity",           // 请求路径
                                                type:"post",                  // 请求的方式，不区分大小写
                                                cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                                contentType:"application/json;charset=utf-8",
                                                data: JSON.stringify({
                                                    title:title,
                                                    context:context
                                                }),
                                                datatype:"json",        // 返回类型，text文本、html页面、json数据
                                                success:function(response){
                                                    console.log("返回: " + response);
                                                    if(response.code === 200) {
                                                        layer.msg("新增活动成功!");
                                                        layer.close(index);                         // 关闭当前窗口
                                                        tableFlush();
                                                    }
                                                },
                                                error:function(response){
                                                    console.log("出错返回: " + response);
                                                }
                                            });
                                        }
                                        ,success: function(layero){

                                        }
                                    });
                                    break
                            }
                        });

                        //监听行工具事件
                        table.on('tool(test)', function(obj){
                            var data = obj.data;
                            //console.log(obj)
                            layer.confirm('真的删除行么', function(index){
                                if(obj.event === 'del'){
                                    $.ajax({
                                        url:"/room/deleteById",
                                        type:'post',
                                        data:{
                                            id:1
                                        },
                                        datatype:"json",
                                        success:function(response){
                                            console.log("返回: " + response);
                                            if(response.code === 200) {
                                                layer.msg("删除用户成功!");
                                                layer.close(index);                         // 关闭当前窗口
                                                tableFlush();
                                            }
                                        },
                                        error:function(response){
                                            console.log("出错返回: " + response);
                                        }
                                    })
                                }
                            });
                        });
                    });
                }
            </script>

            <br><br>
        </div>
    </div>
    <div class="layui-footer">
        <!-- 底部固定区域 -->
        <p style="
        ">酒店活动页面</p>
    </div>
</div>

<script src="../layui/layui.js"></script>
<script>
    //JS
    layui.use(['element', 'layer', 'util'], function(){
        var element = layui.element;
        var layer = layui.layer;
        var util = layui.util;
        var $ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            menuLeft: function(othis){ // 左侧菜单事件
                layer.msg('展开左侧菜单的操作', {icon: 0});
            },
            menuRight: function(){  // 右侧菜单事件
                layer.open({
                    type: 1,
                    title: '更多',
                    content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
                    area: ['260px', '100%'],
                    offset: 'rt', // 右上角
                    anim: 'slideLeft', // 从右侧抽屉滑出
                    shadeClose: true,
                    scrollbar: false
                });
            }
        });
    });
</script>
</body>
</html>